package com.jiazhong.spring.ioc.mybatis;

import com.jiazhong.commons.bean.Emp;
import com.jiazhong.commons.util.JsonResult;
import com.jiazhong.spring.ioc.mybatis.service.EmpService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.List;

public class App {

    private static void a() {
        ApplicationContext beans = new AnnotationConfigApplicationContext("com.jiazhong.spring.ioc.mybatis");
        EmpService empService = beans.getBean(EmpService.class);
        JsonResult result = empService.findAll();
        System.out.println(result);
    }

    private static void b() {
        ApplicationContext beans = new AnnotationConfigApplicationContext("com.jiazhong.spring.ioc.mybatis");
        EmpService empService = beans.getBean(EmpService.class);
        JsonResult result = empService.findByPage(1, 10);
        System.out.println(result);
    }

    private static void c() {
        ApplicationContext beans = new AnnotationConfigApplicationContext("com.jiazhong.spring.ioc.mybatis");
        EmpService empService = beans.getBean(EmpService.class);
        JsonResult result = empService.findByEname("张");
        System.out.println(result);
    }


    private static void d() {
        ApplicationContext beans = new AnnotationConfigApplicationContext("com.jiazhong.spring.ioc.mybatis");
        EmpService empService = beans.getBean(EmpService.class);
        JsonResult result = empService.findById(7980);
        System.out.println(result);
    }

    private static void f() {
        ApplicationContext beans = new AnnotationConfigApplicationContext("com.jiazhong.spring.ioc.mybatis");
        EmpService empService = beans.getBean(EmpService.class);
        JsonResult result = empService.removeById(8051);
        System.out.println(result);
    }

    private static void e() {
        ApplicationContext beans = new AnnotationConfigApplicationContext("com.jiazhong.spring.ioc.mybatis");
        EmpService empService = beans.getBean(EmpService.class);
        Emp emp = new Emp();
        emp.setEname("晁化雨");
        emp.setJob("检测人员");
        emp.setComm(null);
        emp.setSal(9900.0);
        emp.setDeptNo(40);
        emp.setMgr(7954);
        JsonResult result = empService.saveOrUpdate(emp);
        System.out.println(result);
    }
    private static void g() {
        ApplicationContext beans = new AnnotationConfigApplicationContext("com.jiazhong.spring.ioc.mybatis");
        EmpService empService = beans.getBean(EmpService.class);
        Emp emp = new Emp();
        emp.setEname("蔡敏");
        emp.setJob("相声大师");
        emp.setComm(8200.0);
        emp.setSal(3400.0);
        emp.setDeptNo(20);
        emp.setMgr(7909);
        emp.setEmpNo(8035);
        JsonResult result = empService.saveOrUpdate(emp);
        System.out.println(result);
    }

    public static void main(String[] args) {
        g();
    }
}